﻿#This file defines all events for the Top bar buttons.
#Created: 12/11 - 2011
#By: Adam Lewenhaupt

def ConsoleButton_OnClick(s, e):
    Engine.OpenConsole()

def ReloadButton_OnClick(s, e):
    Engine.Reload()
    
def SaveButton_OnClick(s,e):
    worker = BackgroundWorker()
    worker.DoWork += lambda_save
    worker.RunWorkerAsync()

    
def lambda_save(s, e):
    savebox = smf.SaveBox()
    result = savebox.ShowDialog()
    if result == swf.DialogResult.OK:
        saveMap(BasePath + savebox.Path)
    savebox.Dispose()

def LoadButton_OnClick(s,e):
    loadMap(BasePath + "test0.srm", mapdb)

    
def saveMap(path):
    map = maps.Map(mapWidth, mapHeight)
    map.Initialize(mxf.Rectangle.Empty)
    map.SetTiles(Engine['workbench'].Tiles)
    map.Save(path)


def loadMap(path, mapdb):
    map = maps.Map.Load(path, mapdb)
    Engine['workbench'].SetTiles(map.Tiles)